<?php

class DownloadAction extends CommonAction {

    

    public function _initialize() {

        parent::_initialize();
    }
    
    public function index() {
        $map = array();
        import("@.ORG.Util.Page");       //导入分页类
        $model = M('Download');
        $version = $this->_get('version');
        if ($version) {
            $map['download_version'] = $version;
            
            $this->assign('version', $version);
        }

        $count = $model->where($map)->count();    //计算总数

        $p = new Page($count, 10);
        $rows = $model
                ->where($map)
                ->limit($p->firstRow . ',' . $p->listRows)
                ->order('download_id desc')
                ->select();
        $page = $p->show();            //分页的导航条的输出变量
        $this->assign("page", $page);
        $this->assign("count", $count);
        $this->assign("rows", $rows); //数据循环变量
        
        $day = 3600*24;
        $end = date('Y-m-d H:i:s', time());
        $begin = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime("+0 day"))));
        $map['download_at'] = array('between', array($begin, $end));
        $countToday = $model->where($map)->count(); 
        $this->assign("countToday", $countToday);
        
        $end = date('Y-m-d H:i:s', time()-$day);
        $begin = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime("-1 day"))));
        $map['download_at'] = array('between', array($begin, $end));
        $countYesterday = $model->where($map)->count(); 
        $this->assign("countYesterday", $countYesterday);
        
        $end = date('Y-m-d H:i:s', time());
        $begin = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime("-7 day"))));
        $map['download_at'] = array('between', array($begin, $end));
        $countWeek = $model->where($map)->count(); 
        $this->assign("countWeek", $countWeek);
        
        $end = date('Y-m-d H:i:s', time());
        $begin = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime("-30 day"))));
        $map['download_at'] = array('between', array($begin, $end));
        $countMonth = $model->where($map)->count(); 
        $this->assign("countMonth", $countMonth);
        
        $this->display('index');
    }


}